package com.github.ghsea.sso.client.security.permission.http;

import com.github.ghsea.sso.client.security.permission.PermissionManager;
import com.github.ghsea.sso.client.config.ShiroConfig;
import com.github.ghsea.sso.client.security.permission.RolesAndPermissions;
import com.google.gson.reflect.TypeToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author guhai
 */
@Service(value = "PermissionManagerHttpImpl")
public class PermissionManagerHttpImpl extends AbstractRestInvoker<RolesAndPermissions> implements PermissionManager {

    @Autowired
    private ShiroConfig shiroConfig;

    @Override
    public RolesAndPermissions getPermissions(String id, String mail) {
        String apiUrlGetPermissions = shiroConfig.getApiUrlGetPermissions();
        String url = apiUrlGetPermissions.replaceAll(" ", "").replace("{id}", id == null ? "" : id).replace("{mail}", mail);
        return super.invoke(url);
    }

    @Override
    TypeToken responseTypeToken() {
        return new TypeToken<RestResponse<RolesAndPermissions>>() {
        };
    }
}
